package com.niit.listener;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import com.niit.dao.BookDao;
import com.niit.dao.impl.BookDaoImpl;
import com.niit.entity.Book;
import com.niit.utils.MD5Util;
import com.niit.view.LoginView;
import com.niit.view.MainView;

public class SearchListener extends MouseAdapter {
	private MainView view;
	private BookDao dao ;
	public SearchListener(MainView view){
		this.view = view;
		this.dao = new BookDaoImpl();
	}
	
	//当点击查询时执行此方法
	@Override
	public void mouseClicked(MouseEvent e) {
		//获取要查询的书名
		String bookName = view.getBookNameTextField().getText();
		//select * from sys_books where book_name like "%java%";
		Vector<Book> bookList = dao.bookList(bookName);
		System.out.println(bookList);
		Vector<Vector> v = new Vector<Vector>();
		for(Book b : bookList) {
			Vector ve = new Vector();
			ve.add(b.getId());
			ve.add(b.getBookName());
			ve.add(b.getBookAuthor());
			ve.add(b.getBookPrice());
			ve.add(b.getBookPublisher());
			ve.add(b.getCreateTime());
			ve.add("修改");
			ve.add(new JButton("删除"));
			v.add(ve);
		}
		view.dispose();
		new MainView(v);
	}
}
